﻿@model qltscd.Models.ScreenClient.DanhMucThietBiTheoHopDong
@{
    ViewBag.Title = "NhapTheoHopDong";
    Layout = "~/Views/Shared/Modules/_LayoutTacVuNhapLieu.cshtml";
}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script type="text/javascript">
    function openWindow() {
        var window = getWindow();
        window.center();
        window.open();
    }
    function closeWindow() {
        var window = getWindow();
        window.close();
    }
    function getWindow() {
        return $('#wdSearch').data('tWindow');
    }
    function onOpenWindow() {
        document.getElementById('mahopdong').value = '';
        document.getElementById('mahopdong').focus();
    }
    function submitForm() {
        document.location = "/QuanLyThietBi/DanhMucThietBi/NhapTheoHopDong/?MaHopDong=" + document.getElementById('mahopdong').value;
    }

    function submitTaoThietBiTheoHopDong(kieu) {
        document.getElementById("kieuLuu").value = kieu;
        document.forms["TaoThietBiTheoHopDong"].submit();
    }

    function DatePickerOnBlur() {
        var ThoiDiemKhauHao = document.getElementById('ThoiDiemKhauHao');
        if (ThoiDiemKhauHao.value != null && ThoiDiemKhauHao.value != "") {
            if (ThoiDiemKhauHao.value.length == 6) {
                ThoiDiemKhauHao.value = ThoiDiemKhauHao.value[0] + ThoiDiemKhauHao.value[1] + "/"
                + ThoiDiemKhauHao.value[2] + ThoiDiemKhauHao.value[3] + "/"
                + "20" + ThoiDiemKhauHao.value[4] + ThoiDiemKhauHao.value[5];
            }
        }
    }

    function onlyNumbers(e) {
        var keynum;
        var keychar;
        var numcheck;

        if (window.event) // IE8 and earlier
        {
            keynum = e.keyCode;
        }
        else if (e.which) // IE9/Firefox/Chrome/Opera/Safari
        {
            keynum = e.which;
        }
        keychar = String.fromCharCode(keynum);
        numcheck = new RegExp("[0-9/]");
        return numcheck.test(keychar);
    }
</script>
@(
 Html.Telerik().Window()
        .Name("wdSearch")
        .Height(100)
        .Title("Tìm hợp đồng")
            .Resizable(r => r.Enabled(false))
        .Width(400)
        .Content(@<text>
@using (Html.BeginForm("Create", "DanhMucThietBi", FormMethod.Post, new { @id = "TimHopDong" })) {
    <text>
    <div style="width: 100%; height: auto; text-align: left;">
        Mã hợp đồng:
        <input type="text" style="width: 70%" name="mahopdong" id="mahopdong" />
    </div>
    <div style="width: 100%; height: auto; text-align: center; padding-top: 15px;">
        <input type="button" value="Tìm hợp đồng" class="button" onclick="submitForm()" />
        <input type="button" value="Đóng" onclick="closeWindow();" class="button" />
    </div>
    </text>
}
</text>)
        .Modal(true)
        .Buttons(button => {
            button.Close();
        })
        .Visible(false)
        .Draggable(true)
        .Resizable()
        .ClientEvents(e => e.OnOpen("onOpenWindow"))
)
@using (Html.BeginForm("NhapTheoHopDong", "DanhMucThietBi", FormMethod.Post, new { @id = "TaoThietBiTheoHopDong" })) {
    @Html.ValidationSummary(true)
    <input type="hidden" name="kieuLuu" id="kieuLuu" value="0" />
    <fieldset>
        <legend>Thông tin chung</legend>
        <table border="0" width="100%" cellpadding="10px" cellspacing="10px">
            <tr>
                <td style="margin-left: 10px;" class="label_col">
                    Hợp đồng
                </td>
                <td>
                    @(Html.Telerik().ComboBox()
                        .Name("IdentityHopDong")
                        .HtmlAttributes(new { @style = "width:97%;" })
                        .InputHtmlAttributes(new { @style = "width:100%; " })
                        .BindTo((SelectList)ViewBag.IdentityHopDong)
                        .ClientEvents(e => e.OnChange("comboBox_onChange"))
                    )
                </td>
                <td style="margin-left: 10px;" class="label_col">
                    Nhà cung cấp
                </td>
                <td>
                    @(Html.Telerik().ComboBox()
                    .Name("IdentityNhaCungCap")
                    .HtmlAttributes(new { @style = "width:97%;" })
                    .InputHtmlAttributes(new { @style = "width:100%; " })
                    .BindTo((SelectList)ViewBag.IdentityNhaCungCap)
                )
                </td>
            </tr>
            <tr>
                <td style="margin-left: 10px;" class="label_col">
                    Tỉ giá
                </td>
                <td>
                    @(Html.Telerik().CurrencyTextBox()
                        .Name("TiGia")
                        .HtmlAttributes(new { @style = "width:97%; " })
                        .InputHtmlAttributes(new { @style = "width:100%; " })
                        .MinValue(0)
                        .DecimalDigits(3)
                        .EmptyMessage("Nhập tỉ giá")
                        .CurrencySymbol(" ")
                    )
                </td>
                <td style="margin-left: 10px;" class="label_col">
                    Thời điểm khấu hao
                </td>
                <td>
                    @(Html.Telerik().DatePicker()
            .Name("ThoiDiemKhauHao")
                        .HtmlAttributes(new { @style = "width:97%; " })
                        .InputHtmlAttributes(new { @style = "width:100%; " })
                    )
                </td>
            </tr>
            <tr>
                <td style="margin-left: 10px;" class="label_col">
                    Lý do tăng
                </td>
                <td>
                    @(Html.Telerik().ComboBox()
                        .Name("IdentityLyDoTang")
                        .HtmlAttributes(new { @style = "width:97%;" })
                        .InputHtmlAttributes(new { @style = "width:100%; " })
                        .BindTo((SelectList)ViewBag.IdentityLyDoTang)
                    )
                </td>
                <td style="margin-left: 10px;" class="label_col">
                    Thời điểm bảo hành
                </td>
                <td>
                    @(Html.Telerik().DatePicker()
                        .Name("ThoiDiemBaoHanh")
                        .HtmlAttributes(new { @style = "width:97%; " })
                        .InputHtmlAttributes(new { @style = "width:100%; " })
                    )
                </td>
            </tr>
            <tr>
                <td style="margin-left: 10px;" class="label_col">
                    Loại tiền
                </td>
                <td>
                    @(Html.Telerik().ComboBox()
                    .Name("IdentityLoaiTien")
                    .HtmlAttributes(new { @style = "width:97%;" })
                    .InputHtmlAttributes(new { @style = "width:100%; " })
                    .BindTo((SelectList)ViewBag.IdentityLoaiTien)
                )
                </td>
                <td style="margin-left: 10px;" class="label_col">
                </td>
                <td>
                </td>
            </tr>
        </table>
    </fieldset>
    <fieldset style="width: 100%;">
        <legend>Thông tin thiết bị</legend>
        @(
 Html.Telerik().Grid(Model.DSThietBi)
    .Name("grdDSTB")
    .DataKeys(keys => {
        keys.Add(c => c.MaThietBi);
    })
    .Selectable()
    .Resizable(r => r.Columns(true))
    .Reorderable(r => r.Columns(true))
    .Sortable()
    .Scrollable(s => s.Height(200).Enabled(true))

    .Pageable(paging => paging.Enabled(true).Style(GridPagerStyles.NextPreviousAndInput).PageSize(5))
    .Editable(e => e.Mode(GridEditMode.InCell))
    .NoRecordsTemplate("Không có thiết bị")
    .ToolBar(t => {
        t.Insert()
           .Text("Thêm thiết bị")
           .ButtonType(GridButtonType.ImageAndText);
        t.SubmitChanges().SaveText("Lưu").CancelText("Hủy").ButtonType(GridButtonType.ImageAndText);
    })
    .DataBinding(databinding => {
        databinding.Server()
            .Select("NhapTheoHopDong", "DanhMucThietBi");
        databinding.Ajax()
            .Select("_NhapTheoHopDong", "DanhMucThietBi")
            .Update("_UpdateDanhMucHopDong", "DanhMucThietBi");
    })
    .Columns(column => {
        column.Command(cmd => {
            cmd.Delete()
                .ButtonType(GridButtonType.Image)
                .Text("Xóa");
        }).Width(40);
        column.Bound(i => i.IdentityThietBi).Visible(false);
        column.Bound(o => o.MaThietBi).Title("Mã thiết bị").Width(100);
        column.Bound(o => o.TheThietBi).Title("Thẻ thiết bị").Width(100);
        column.Bound(o => o.SerialThietBi).Title("Serial thiết bị").Width(100);
        column.Bound(o => o.TenThietBi).Title("Tên thiết bị").Width(100);
        column.Bound(o => o.MaThietBiCha)
            .Title("Thiết bị cha")
            .EditorTemplateName("ThietBi")
            .Width(100);
        column.Bound(o => o.NSX)
            .Title("Năm sản xuất")
            .EditorTemplateName("NamSanXuat")
            .Width(100);
        column.Bound(o => o.NCC)
            .Title("Năm cung cấp")
            .EditorTemplateName("NamCungCap")
            .Width(100);
        column.Bound(o => o.NguyenGia)
            .Title("Nguyên giá")
            .EditorTemplateName("NguyenGia")
            .Width(100);
        column.Bound(o => o.ThoiGianBaoHanh)
            .Title("T/G bảo hành")
            .EditorTemplateName("ThoiGianBaoHanh")
            .Width(100);
        column.Bound(o => o.ThoiGianKhauHao)
            .Title("T/G khấu hao")
            .EditorTemplateName("ThoiGianKhauHao")
            .Width(100);
        column.Bound(o => o.ChatLuong)
            .Title("Chất lượng")
            .Width(100);
    })
)
    </fieldset>
    <div class="divButton">
        <input type="submit" value="Lưu" class="button" onclick="return onSubmit();" />&nbsp;
        <input type="button" value="Tìm hợp đồng" class="button" onclick="openWindow();" />&nbsp;
        <input type="reset" value="Nhập lại" class="button" />&nbsp;
        @Html.ActionLink("Thoát", "Index", "TacVu", null, new { @class = "button" })
    </div>
}
<div class="errBlock">
    @ViewData["errMaThietBi"]
    @Html.ValidationMessageFor(model => model.IdentityHopDong, "", new { @style = "display: block;" })
    @Html.ValidationMessageFor(model => model.IdentityNhaCungCap, "", new { @style = "display: block;" })
    <span style="display: block;" id="abc"></span>
    @Html.ValidationMessageFor(model => model.ThoiGianKhauHao, "", new { @style = "display: block;" })
    @Html.ValidationMessageFor(model => model.ThoiDiemKhauHao, "", new { @style = "display: block;" })
    @Html.ValidationMessageFor(model => model.ThoiDiemBaoHanh, "", new { @style = "display: block;" })
    @Html.ValidationMessageFor(model => model.IdentityLoaiTien, "", new { @style = "display: block;" })
    @Html.ValidationMessageFor(model => model.IdentityLyDoTang, "", new { @style = "display: block;" })
    @Html.ValidationMessageFor(model => model.TiGia, "", new { @style = "display: block;" })
</div>
<script type="text/javascript">
    function onSubmit() {
        if ($('#IdentityHopDong').data('tComboBox').value() == null
            || $('#IdentityHopDong').data('tComboBox').value() == "") {
            document.getElementById('abc').innerHTML = "Hợp đồng không được để trống";
            return false;
        }
        return true;
    }
    function comboBox_onChange() {
        if ($('#IdentityHopDong').data('tComboBox').value() != null
        || $('#IdentityHopDong').data('tComboBox').value() != "") {
            document.getElementById('abc').innerHTML = "";
        }
    }
    function reloadGrid() {
        $('#grdDSTB').data('tGrid').rebind();
    }
</script>
